<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小菊AI问诊 - 登录</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui@2.6.8/dist/css/layui.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background: linear-gradient(135deg, #f5f9fc 0%, #e8f5e9 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
            padding: 15px;
        }

        .login-container {
            width: 100%;
            max-width: 1200px;
            margin: 0 auto;
        }

        .login-card {
            background-color: white;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(46, 125, 50, 0.15);
            overflow: hidden;
            display: flex;
            min-height: 600px;
        }

        .login-left {
            background: linear-gradient(rgba(56, 142, 60, 0.85), rgba(46, 125, 50, 0.9)), url('http://8.130.34.212:7301/api/v1/buckets/xiaoju/objects/download?preview=true&prefix=auth_bg.jpg&version_id=null') center/cover;
            color: white;
            padding: 50px 40px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            flex: 1.2;
        }

        .login-right {
            padding: 50px 40px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            flex: 1;
        }

        .brand-text {
            font-size: 42px;
            font-weight: 800;
            margin-bottom: 25px;
            color: white;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
            letter-spacing: 1px;
        }

        .welcome-text {
            font-size: 32px;
            font-weight: 600;
            margin-bottom: 20px;
            color: white;
        }

        .feature-list {
            list-style: none;
            padding: 0;
            margin-top: 30px;
        }

        .feature-list li {
            margin-bottom: 20px;
            display: flex;
            align-items: flex-start;
            font-size: 18px;
            line-height: 1.6;
        }

        .feature-list i {
            margin-right: 15px;
            font-size: 24px;
            color: #fff;
            background: rgba(255, 255, 255, 0.2);
            width: 45px;
            height: 45px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }

        .login-title {
            text-align: center;
            font-size: 32px;
            font-weight: 700;
            color: #2e7d32;
            margin-bottom: 35px;
            position: relative;
        }

        .login-title:after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 4px;
            background: #4caf50;
            border-radius: 2px;
        }

        .divider {
            text-align: center;
            position: relative;
            margin: 25px 0;
        }

        .divider:before {
            content: "";
            position: absolute;
            top: 50%;
            left: 0;
            right: 0;
            height: 1px;
            background-color: #e0e0e0;
            z-index: 1;
        }

        .divider-text {
            display: inline-block;
            background-color: white;
            padding: 0 15px;
            position: relative;
            z-index: 2;
            color: #757575;
            font-size: 14px;
        }

        .login-footer {
            text-align: center;
            margin-top: 30px;
            color: #666;
            font-size: 14px;
        }

        .login-footer a {
            color: #2e7d32;
            text-decoration: none;
            font-weight: 500;
        }

        .login-footer a:hover {
            text-decoration: underline;
        }

        .remember-forgot {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
        }

        .layui-form-item {
            margin-bottom: 25px;
        }

        .layui-input {
            height: 50px;
            border-radius: 8px;
            border: 1px solid #e0e0e0;
            padding-left: 20px;
            font-size: 16px;
            transition: all 0.3s;
        }

        .layui-input:focus {
            border-color: #4caf50;
            box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
        }

        .layui-btn {
            height: 50px;
            line-height: 50px;
            border-radius: 8px;
            font-size: 18px;
            background: #2e7d32;
            transition: all 0.3s;
        }

        .layui-btn:hover {
            background: #1b5e20;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(46, 125, 50, 0.3);
        }

        .layui-form-checkbox {
            margin-top: 3px;
        }

        .layui-form-checked[lay-skin=primary] i {
            background-color: #2e7d32;
            border-color: #2e7d32;
        }

        .forgot-link {
            color: #2e7d32;
            font-weight: 500;
        }

        .forgot-link:hover {
            text-decoration: underline;
        }

        .register-link {
            color: #2e7d32;
            font-weight: 600;
        }

        /* 手机端优化 */
        @media (max-width: 992px) {
            .login-left {
                display: none; /* 在平板和手机上隐藏左侧区域 */
            }

            .login-right {
                width: 100%;
                padding: 40px 30px;
            }

            .login-title {
                font-size: 28px;
            }
        }

        @media (max-width: 768px) {
            .login-right {
                padding: 35px 25px;
            }

            .login-title {
                font-size: 26px;
                margin-bottom: 25px;
            }

            .layui-input {
                height: 48px;
                font-size: 16px;
            }

            .layui-btn {
                height: 48px;
                line-height: 48px;
                font-size: 17px;
            }
        }

        @media (max-width: 576px) {
            body {
                padding: 10px;
                background: white;
            }

            .login-container {
                width: 100%;
            }

            .login-card {
                min-height: auto;
                box-shadow: none;
                border-radius: 0;
            }

            .login-right {
                padding: 30px 20px;
            }

            .login-title {
                font-size: 24px;
                margin-bottom: 20px;
            }

            .login-title:after {
                width: 60px;
                height: 3px;
                bottom: -8px;
            }

            .layui-form-item {
                margin-bottom: 20px;
            }

            .layui-input {
                height: 46px;
                font-size: 15px;
                padding-left: 15px;
            }

            .layui-btn {
                height: 46px;
                line-height: 46px;
                font-size: 16px;
            }

            .remember-forgot {
                flex-direction: column;
                align-items: flex-start;
                margin-bottom: 15px;
            }

            .remember-forgot .layui-form-item {
                margin-bottom: 10px;
            }

            .login-footer {
                margin-top: 25px;
                font-size: 13px;
            }
        }

        /* 针对430x932分辨率的优化 */
        @media (max-width: 480px) and (max-height: 932px) {
            .login-right {
                padding: 25px 20px;
                justify-content: flex-start;
            }

            .mobile-brand {
                display: block;
                margin-bottom: 15px;
            }

            .login-title {
                font-size: 22px;
                margin-bottom: 15px;
            }

            .layui-form-item {
                margin-bottom: 20px;
            }

            .layui-input {
                height: 44px;
                font-size: 14px;
            }

            .layui-btn {
                height: 44px;
                line-height: 44px;
                font-size: 16px;
            }

            .remember-forgot {
                margin-bottom: 10px;
            }

            .login-footer {
                margin-top: 20px;
            }
        }

        @media (max-width: 360px) {
            .login-right {
                padding: 25px 15px;
            }

            .login-title {
                font-size: 22px;
            }

            .layui-input {
                height: 44px;
                font-size: 14px;
            }

            .layui-btn {
                height: 44px;
                line-height: 44px;
                font-size: 15px;
            }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-card">
            <!-- 左侧欢迎区域（在手机上隐藏） -->
            <div class="login-left">
                <div class="brand-text">小菊AI问诊</div>
                <div class="welcome-text">欢迎回来</div>
                <p>请登录您的账户以继续使用我们的AI问诊服务</p>

                <ul class="feature-list">
                    <li>
                        <i class="fas fa-brain"></i>
                        <div>AI智能诊断，精准识别健康问题<br><small>基于深度学习的医学诊断模型</small></div>
                    </li>
                    <li>
                        <i class="fas fa-clock"></i>
                        <div>7×24小时AI医生在线咨询<br><small>随时解答您的健康疑问</small></div>
                    </li>
                    <li>
                        <i class="fas fa-chart-line"></i>
                        <div>个性化健康分析与趋势预测<br><small>提供专属健康管理方案</small></div>
                    </li>
                    <li>
                        <i class="fas fa-shield-alt"></i>
                        <div>医疗级数据加密与隐私保护<br><small>您的健康数据绝对安全</small></div>
                    </li>
                </ul>
            </div>

            <!-- 右侧登录表单 -->
            <div class="login-right">
                <!-- 手机端显示的品牌标识 -->
                <div class="mobile-brand" style="display: none; text-align: center; margin-bottom: 20px;">
                    <div style="font-size: 28px; font-weight: 700; color: #2e7d32;">小菊AI问诊</div>
                    <div style="font-size: 16px; color: #666; margin-top: 5px;">智能医疗健康服务平台</div>
                </div>

                <h2 class="login-title">账户登录</h2>

                <form class="layui-form" action="">
                    <div class="layui-form-item">
                            <input type="email" name="email" lay-verify="required|email" placeholder="请输入邮箱地址" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-form-item">
                            <input type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>

                    <div class="remember-forgot">
                        <div class="layui-form-item">
                                <input type="checkbox" name="remember" title="记住我" lay-skin="primary">
                        </div>
                        <div>
                            <a href="#" class="forgot-link">忘记密码?</a>
                        </div>
                    </div>

                    <div class="layui-form-item">
                            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登录</button>
                    </div>
                </form>

                <div class="login-footer">
                    还没有账户? <a href="#" class="register-link">立即注册</a><br>
                    <span style="font-size: 12px; margin-top: 10px; display: block;">© 2025 小菊AI问诊 版权所有</span>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/layui@2.6.8/dist/layui.min.js"></script>
    <script src="/static/js/api_config.js"></script>
    <script>
        layui.use(['form', 'layer'], function(){
            var form = layui.form;
            var layer = layui.layer;

            // 检测设备类型，在手机上显示品牌标识
            function checkDevice() {
                if (window.innerWidth <= 992) {
                    document.querySelector('.mobile-brand').style.display = 'block';
                } else {
                    document.querySelector('.mobile-brand').style.display = 'none';
                }
            }

            // 初始检测
            checkDevice();

            // 窗口大小变化时检测
            window.addEventListener('resize', checkDevice);

            // 表单验证和提交
            form.on('submit(login)', function(data){
                // 显示加载状态
                var loadIndex = layer.load(0, {shade: [0.2, '#fff']});
                console.log('Form data submitted:', data.field);

                // 直接使用fetch API进行登录请求
                fetch('/api/auth/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data.field)
                })
                .then(function(response) {
                    layer.close(loadIndex);
                    console.log('Login response status:', response.status);
                    console.log('Login response headers:', Object.fromEntries(response.headers));
                    
                    // 无论HTTP状态码如何，都尝试解析JSON
                    return response.json().then(function(data) {
                        console.log('Login response data:', data);
                        console.log('Response code:', data.code);
                        console.log('Response data structure:', JSON.stringify(data.data, null, 2));
                        
                        if (data.code === 200 && data.data && data.data.access_token) {
                            // 存储token到localStorage
                            localStorage.setItem('access_token', data.data.access_token);
                            localStorage.setItem('token_type', data.data.token_type || 'bearer');
                            localStorage.setItem('user', JSON.stringify(data.data.user || {}));
                            
                            // 验证存储是否成功
                            console.log('Token stored:', localStorage.getItem('access_token') ? 'Yes' : 'No');
                            console.log('Stored token length:', localStorage.getItem('access_token')?.length || 0);
                            
                            layer.msg('登录成功！Token已存储', {
                                icon: 1,
                                time: 1500
                            }, function(){
                                // 登录成功后跳转到仪表盘或首页
                                console.log('Redirecting to admin page...');
                                window.location.href = '/admin/';
                            });
                        } else {
                            console.error('Login failed, code:', data.code);
                            console.error('Missing token in response:', !data.data || !data.data.access_token);
                            layer.msg(data.message || '登录失败，请重试', {
                                icon: 5,
                                time: 2000
                            });
                        }
                    });
                })
                .catch(function(error) {
                    layer.close(loadIndex);
                    console.error('Login error:', error);
                    layer.msg('登录失败：' + (error.message || '网络错误'), {
                        icon: 5,
                        time: 2000
                    });
                });

                return false;
            });
        });
    </script>
</body>
</html>